home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 December / PCWDEC06.iso / Software / Trial / Paint Shop Pro XI / Data1.cab / ccc.js < prev    next >
Encoding:
JavaScript  |  2006-08-04  |  9.2 KB  |  380 lines

  1. // JScript source code
  2.  
  3. // parameter values used
  4. var strTotalDays = "TotalDays";
  5. var strUsedDays = "NumDays";
  6.  
  7. // rgb colour values
  8. var strRed = "red";
  9. var strGrn = "green";
  10. var strRedRGB = "rgb(184,29,3)"
  11. var strGrnRGB = "rgb(31,156,35)";
  12.  
  13. // standard graphics paths for single pixel border graphics
  14. var strBdrRed = "url('Images\\TrialCounter\\red1.png')";
  15. var strBdrGrn = "url('Images\\TrialCounter\\green1.png')";
  16.  
  17. // standard graphics paths for box corners
  18. var strBasePath = "Images\\TrialCounter\\";
  19. var strTL = "_t_l.gif";
  20. var strTR = "_t_r.gif";
  21. var strBL = "_b_l.gif";
  22. var strBR = "_b_r.gif";
  23.  
  24. function reLayout(strURL)
  25. {
  26.     // only do this if the counter is to be shown
  27.     var strShow = extractParam(strURL, "ShowCounter");
  28.     if(strShow.toLowerCase() == "yes")
  29.     {
  30.         // show the count
  31.         var tdPromo = document.getElementById("tdPromo")
  32.         if (tdPromo != null)
  33.         {
  34.             tdPromo.style.display = "";
  35.         }
  36.         var divTrialRemain = document.getElementById("divTrialRemain")
  37.         if (divTrialRemain != null)
  38.         {
  39.             divTrialRemain.style.display = "";
  40.         }
  41.         
  42.         var divCount1 = document.getElementById("divCountBottom1");
  43.         var divCount2 = document.getElementById("divCountBottom2");
  44.         if ((divCount1 != null) && (divCount2 != null))
  45.         {
  46.             var strST = extractParam(strURL, "ST");
  47.             if ((strST == "1") || (strST == "3"))
  48.             {
  49.                 divCount1.style.display = "none";
  50.                 divCount2.style.display = "";
  51.             }
  52.         }
  53.         
  54.  
  55.         var elmCount = document.getElementById("divCountDown");
  56.         
  57.         // get the values for the trail total and trial remaining
  58.         var strTrialTotal = extractParam(strURL,strTotalDays);
  59.         var strDaysRemain = extractParam(strURL,strUsedDays);
  60.         
  61.         // get an int value for each number
  62.         var nTrialTotal = 0;
  63.         if(strTrialTotal.length  > 0)
  64.         {
  65.             nTrialTotal = parseInt(strTrialTotal,10);
  66.         }
  67.         var nDaysRemain = 0;
  68.         if(strDaysRemain.length > 0)
  69.         {
  70.             nDaysRemain = parseInt(strDaysRemain,10);
  71.         }
  72.         if (nDaysRemain < 0)
  73.         {
  74.             nDaysRemain = 0;
  75.         }
  76.         
  77.         // insert the days remaining into the document
  78.         var elmCounter = document.getElementById("divCount");
  79.         if(null != elmCounter)
  80.         {
  81.             elmCounter.innerText = String(nDaysRemain);
  82.         }
  83.         
  84.         // adust the size of the progress bar
  85.         var elmTopSlider = document.getElementById("divOverSlider");
  86.         var elmBotSlider = document.getElementById("divUnderSlider");        
  87.         if(nTrialTotal > 0)
  88.         {
  89.             if(null != elmTopSlider)
  90.             {
  91.                 // get the days remaining as a percentage
  92.                 var nPercent = (nDaysRemain / nTrialTotal);
  93.                 if(nPercent > 1)
  94.                 {
  95.                     nPercent = 1;
  96.                 }
  97.                 
  98.                 // get the total length of the progress bar and computer the desired
  99.                 // length of the slider
  100.                 if(null != elmBotSlider)
  101.                 {
  102.                     var nTotalWidth = parseInt(elmBotSlider.offsetWidth);
  103.                     var nPartWidth = (nTotalWidth * nPercent);
  104.                     elmTopSlider.style.width = String(nPartWidth);
  105.                 }
  106.             }
  107.         }
  108.         
  109.         // remove the progress bar
  110.         if((nTrialTotal == 0) )
  111.         {
  112.             if((null != elmCount) && (null != elmTopSlider) && (null != elmBotSlider))
  113.             {
  114.                 // remove the progress bar from the DOM
  115.                 var elmPImgLeft = document.getElementById("divPBStart");
  116.                 var elmPImgRight = document.getElementById("dibPBEnd");
  117.                 if(null != elmPImgLeft)
  118.                 {
  119.                     elmTopSlider.removeChild( elmPImgLeft );
  120.                 }
  121.                 if(null != elmPImgRight)
  122.                 {
  123.                     elmTopSlider.removeChild( elmPImgRight );
  124.                 }
  125.                 
  126.                 elmBotSlider.removeChild( elmTopSlider );
  127.                 elmCount.removeChild( elmBotSlider );
  128.             }            
  129.         }
  130.  
  131.         // we now have to change the colour of several elements as well as swap some graphics
  132.         var strColour = strGrn;
  133.         var strColourRGB = strGrnRGB;    // initial RGB colour
  134.         var strPixel = strBdrGrn;        // initial single pixel border
  135.         if( nDaysRemain == 0 )
  136.         {
  137.             strColour = strRed;
  138.             strColourRGB = strRedRGB;
  139.             strPixel = strBdrRed;
  140.         }        
  141.                 
  142.         // change the colour of the numerical text
  143.         elmCounter.style.color = strColourRGB;
  144.         
  145.         // hook up the border graphics for the straight part of the border
  146.         var elmTop = document.getElementById("bdrTop");
  147.         var elmLft = document.getElementById("bdrLft");
  148.         var elmBtm = document.getElementById("bdrBtm");
  149.         var elmRgt = document.getElementById("bdrRgt");
  150.         
  151.         if(null != elmTop)
  152.         {
  153.             elmTop.style.backgroundImage = strPixel;
  154.         }
  155.         if(null != elmLft)
  156.         {
  157.             elmLft.style.backgroundImage = strPixel;
  158.         }
  159.         if(null != elmBtm)
  160.         {
  161.             elmBtm.style.backgroundImage = strPixel;
  162.         }
  163.         if(null != elmRgt)
  164.         {
  165.             elmRgt.style.backgroundImage = strPixel;
  166.         }
  167.         
  168.         // hook up the graphics for the box corner
  169.         var elmCnrTL = document.getElementById("cnrTL");
  170.         var elmCnrTR = document.getElementById("cnrTR");
  171.         var elmCnrBL = document.getElementById("cnrBL");
  172.         var elmCnrBR = document.getElementById("cnrBR");
  173.         
  174.         if(null != elmCnrTL)
  175.         {
  176.             elmCnrTL.style.backgroundImage = ("url(" + strBasePath.concat(strColour.concat( strTL )) + ")");
  177.         }
  178.         if(null != elmCnrTR)
  179.         {
  180.             elmCnrTR.style.backgroundImage = ("url(" + strBasePath.concat(strColour.concat( strTR )) + ")");
  181.         }
  182.         if(null != elmCnrBL)
  183.         {
  184.             elmCnrBL.style.backgroundImage = ("url(" + strBasePath.concat(strColour.concat( strBL )) + ")");
  185.         }
  186.         if(null != elmCnrBR)
  187.         {
  188.             elmCnrBR.style.backgroundImage = ("url(" + strBasePath.concat(strColour.concat( strBR )) + ")");
  189.         }                        
  190.     }
  191.     else
  192.     {
  193.         var tdPromo = document.getElementById("tdPromo")
  194.         if (tdPromo != null)
  195.         {
  196.             tdPromo.style.display = "none";
  197.         }
  198.         var divTrialRemain = document.getElementById("divTrialRemain")
  199.         if (divTrialRemain != null)
  200.         {
  201.             divTrialRemain.style.display = "none";
  202.         }
  203.     }
  204. }
  205.  
  206. function ShowBanner(strShow)
  207. {
  208.     var bannerTop = document.getElementById("bannerTop");
  209.     var bannerCenter = document.getElementById("bannerCenter");
  210.     var bannerBottom = document.getElementById("bannerBottom");
  211.     if ((bannerTop != null) && (bannerCenter != null) && (bannerBottom != null))
  212.     {
  213.         if ( strShow.toLowerCase() == "no" )
  214.         {
  215.             bannerTop.style.display = "none";
  216.             bannerCenter.style.display = "none";
  217.             bannerBottom.style.display = "none";
  218.         }
  219.         else 
  220.         {
  221.             bannerTop.style.display = "inline";
  222.             bannerCenter.style.display = "inline";
  223.             bannerBottom.style.display = "inline";
  224.         }
  225.     }
  226. }
  227.  
  228. function SetActivationCodeElement()
  229. {
  230.     var strActCode = getParamVal("activationcode");
  231.     var oTxt = document.getElementById("txtActivationCode");
  232.     
  233.     if (strActCode != null && oTxt != null)
  234.         oTxt.value = strActCode.toUpperCase();
  235. }
  236.  
  237. function getParamString()
  238. {
  239.   var sParamString = "";
  240.     var sQueryVar = location.search;
  241.     var nIndex = sQueryVar.indexOf("?");
  242.     if ( nIndex >= 0 )
  243.     {
  244.       sParamString = sQueryVar.substr(nIndex);
  245.   }    
  246.   
  247.   return sParamString;
  248. }
  249.  
  250. function getParamVal(paramName)
  251. {
  252.     var sQueryVar = location.search.toLowerCase();
  253.     return extractParam(sQueryVar, paramName);
  254. }    
  255.  
  256. function extractParam(sQueryVar, paramName)
  257. {
  258.     if (sQueryVar == null || paramName == null)
  259.       return "";
  260.  
  261.     var nIndex = sQueryVar.indexOf("?");
  262.     if (nIndex >= 0)
  263.         sQueryVar = sQueryVar.substr(nIndex + 1);
  264.  
  265.     paramName = paramName.toLowerCase();
  266.  
  267.     var asParams = sQueryVar.split("&");
  268.     var i;
  269.  
  270.     for (i in asParams)
  271.     {
  272.         var pair = asParams[i].split("=");
  273.         if (pair.length == 2)
  274.         {
  275.             if (pair[0].toLowerCase() == paramName)
  276.             {
  277.                 return pair[1];
  278.             }
  279.         }
  280.     }
  281.  
  282.     return "";
  283. }
  284.  
  285. function EnableContinue(bEnable)
  286. {
  287.     var oBtn = document.getElementById("btnContinue");
  288.     if (oBtn != null)
  289.     {
  290.         oBtn.disabled = (bEnable == false);
  291.     }
  292. }
  293.  
  294. function ExpandRelativeURL(sPage)
  295. {
  296.     var sPath = location.pathname;
  297.     var lastbkslsh = sPath.lastIndexOf("\\");
  298.     if (lastbkslsh < 0)
  299.     {
  300.         lastbkslsh = sPath.lastIndexOf("/");
  301.     }
  302.     if (lastbkslsh < 0)
  303.     {
  304.         lastbkslsh = 0;
  305.     }
  306.     sPath = sPath.substr(0, lastbkslsh + 1);
  307.     var sReturn = location.protocol + "//" + location.host + sPath + sPage;
  308.     return sReturn;
  309. }
  310.  
  311. function ValidateSerial(sSerial)
  312. {
  313.     if (sSerial != null && sSerial.match(/^\s*[a-zA-Z]{2}\d{2}[a-zA-Z]{3}-?\d{7}-?[a-zA-Z]{3}(?:\*\d{6})?\s*$/) != null)
  314.     {
  315.         return true;
  316.     }
  317.     return false;
  318. }
  319.  
  320. function ValidateActCode(sCode)
  321. {
  322.     if (sCode != null && sCode.match(/^\s*(?:[a-fA-F0-9]{4}-?){5}\s*$/) != null)
  323.     {
  324.         return true;
  325.     }
  326.     
  327.     return false;
  328. }
  329.  
  330. function FormatSerial(sCode)
  331. {
  332.     if (sCode != null && sCode.length >= 17 && sCode.indexOf("-") == -1)
  333.     {
  334.         var sNewCode = sCode.substr(0,7) + "-" + sCode.substr(7,7) + "-" + sCode.substr(14);
  335.         sNewCode = sNewCode.toUpperCase();
  336.         return sNewCode;
  337.     }
  338.     else
  339.     {
  340.         return sCode;
  341.     }
  342. }
  343.  
  344. function FormatActivationCode(sCode)
  345. {
  346.     if (sCode != null && sCode.length == 20 && sCode.indexOf("-") == -1)
  347.     {
  348.         var sNewCode = sCode.substr(0,4) + "-" + sCode.substr(4,4) + "-" + 
  349.                                      sCode.substr(8,4) + "-" + sCode.substr(12,4) + "-" + sCode.substr(16,4);
  350.         sNewCode = sNewCode.toUpperCase();
  351.         return sNewCode;
  352.     }
  353.     else
  354.     {
  355.         return sCode;
  356.     }
  357. }
  358.  
  359.  
  360. function regChangeLaunchButtonTitle()
  361. {
  362.     var btnClose = document.getElementById("btnClose");
  363.     if ( btnClose != null )
  364.     {
  365.         btnClose.style.display = "inline";
  366.         
  367.         var btnLaunch = document.getElementById("btnLaunch");
  368.         if ( btnLaunch != null )
  369.         {
  370.             btnLaunch.style.display = "none";
  371.         }
  372.     }
  373. }
  374.  
  375. function OnUnlock()
  376. {
  377.     location='pcucmd://Unlock?admin=yes'; 
  378.     location='pcucmd://Next?condition=true'            
  379. }
  380.